home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 76 / DVD Actual 1 Marzo 2003.iso / Trial / TurboCAD 7.1 Pro / Data.Cab / F24511_BlockInsertDialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-10  |  2.4 KB  |  111 lines

  1. // BlockInsertDialog.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "SDKDemo.h"
  6. #include "BlockInsertDialog.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CBlockInsertDialog dialog
  16.  
  17.  
  18. CBlockInsertDialog::CBlockInsertDialog(IDrawing* pIDrawing, CWnd* pParent /*=NULL*/) : 
  19.     CDialog(CBlockInsertDialog::IDD, pParent),
  20.     m_pBlocks(NULL)
  21. {
  22.     //{{AFX_DATA_INIT(CBlockInsertDialog)
  23.     m_strBlockName = _T("");
  24.     //}}AFX_DATA_INIT
  25.  
  26.     if (pIDrawing != NULL)
  27.     {
  28.         Blocks* pBlocks = NULL;
  29.         HRESULT hRes = pIDrawing->get_Blocks(&pBlocks);
  30.         if (SUCCEEDED(hRes))
  31.         {
  32.             long lCount = 0;
  33.             hRes = pBlocks->get_Count(&lCount);
  34.             if (SUCCEEDED(hRes) && lCount > 0)
  35.             {
  36.                 m_pBlocks = pBlocks;
  37.                 return;
  38.             }
  39.             pBlocks->Release();
  40.         }
  41.     }
  42. }
  43.  
  44. CBlockInsertDialog::~CBlockInsertDialog()
  45. {
  46.     if (m_pBlocks != NULL)
  47.         m_pBlocks->Release();
  48. }
  49.  
  50. void CBlockInsertDialog::DoDataExchange(CDataExchange* pDX)
  51. {
  52.     CDialog::DoDataExchange(pDX);
  53.     //{{AFX_DATA_MAP(CBlockInsertDialog)
  54.     DDX_LBString(pDX, IDC_BLOCKS, m_strBlockName);
  55.     //}}AFX_DATA_MAP
  56. }
  57.  
  58. BOOL CBlockInsertDialog::OnInitDialog()
  59. {
  60.     CDialog::OnInitDialog();
  61.  
  62.     BOOL bSuccess = FALSE;
  63.     if (m_pBlocks != NULL)
  64.     {
  65.         long lCount = 0;
  66.         HRESULT hRes = m_pBlocks->get_Count(&lCount);
  67.         if (SUCCEEDED(hRes) && lCount > 0)
  68.         {
  69.             CListBox* pList = (CListBox*)GetDlgItem(IDC_BLOCKS);
  70.             for (long i = 0; i < lCount; ++i)
  71.             {
  72.                 Block* pBlock = NULL;
  73.                 COleVariant varIndex(i);
  74.                 hRes = m_pBlocks->get_Item(&varIndex, &pBlock);
  75.                 if (SUCCEEDED(hRes))
  76.                 {
  77.                     BSTR bstrName = NULL;
  78.                     hRes = pBlock->get_Name(&bstrName);
  79.                     if (SUCCEEDED(hRes))
  80.                     {
  81.                         CString str(bstrName);
  82.                         SysFreeString(bstrName);
  83.  
  84.                         if (pList->AddString(str) != LB_ERR)
  85.                             bSuccess = TRUE;
  86.                     }
  87.                 }
  88.             }
  89.         }
  90.     }
  91.     if (!bSuccess)
  92.         EndDialog(IDCANCEL);
  93.     return TRUE;
  94. }
  95.  
  96. BEGIN_MESSAGE_MAP(CBlockInsertDialog, CDialog)
  97.     //{{AFX_MSG_MAP(CBlockInsertDialog)
  98.     ON_LBN_DBLCLK(IDC_BLOCKS, OnDblclkBlocks)
  99.     //}}AFX_MSG_MAP
  100. END_MESSAGE_MAP()
  101.  
  102. /////////////////////////////////////////////////////////////////////////////
  103. // CBlockInsertDialog message handlers
  104.  
  105. void CBlockInsertDialog::OnDblclkBlocks() 
  106. {
  107.     UpdateData(TRUE);
  108.     EndDialog(IDOK);
  109. }
  110.  
  111.